package com.gyul.findmystock.entity;

import com.gyul.findmystock.util.Utils;

public class QuoteEntity implements Comparable<QuoteEntity>  {
	public int date;
	public int low;
	public int high;
	public int open;
	public int close;
	public long volume;
	
	public QuoteEntity(int date, int low, int high, int open, int close, long volume) {
		this.date = date;
		this.low = low;
		this.high = high;
		this.open = open;
		this.close = close;
		this.volume = volume;
	}
	
	final int SUSPECT_DATE = 19000000;
	
	public String verify() {  
        if(date < SUSPECT_DATE)
        	return "Suspect Date : " +  date + "\n";

        if(date > Utils.getCurrentDate() )
        	return "FUTURE_DATE : " +  date + "\n";

        if( Utils.isWeekend(date) )
        	return "WEEKEND_QUOTE : " +  date + "\n";

        if(low > open || low > close || low > high) {
            low = Math.min(Math.min(open, close), high);
        }

        if(high < open || high < close || high < low) {        	
            high = Math.max(Math.max(open, close), low);
        }

        if(low < 0) {
            low = 0;
        }

        if(high < 0) {
            high = 0;
        }

        if(open < 0) {
            open = 0;
        }

        if(close < 0) {
            close = 0;
        }

        if(volume < 0) {
            volume = 0;
        }

        return null;
    }
	
	@Override
	public int compareTo(QuoteEntity quote) {
		return date - quote.date;		
	}	
	
	public String toString() {		
		return date + " Open : " + open + " Close : " + close + " Low : " + low + " High : " + high + " Volume : " + volume;
	}
	
}
